package masterjava.admingui.shared.entity;

import masterjava.admingui.shared.PhoneType;
import masterjava.common.shared.entity.BaseEntity;

import javax.persistence.*;

/**
 * User: Grigory Kislin
 * Date: 23/06/11
 */
@Entity
@Table(name = "PHONE")
@Access(AccessType.PROPERTY)
public class Phone extends BaseEntity {

    public Phone() {
    }

    public Phone(String number, PhoneType type) {
        this.number = number;
        this.type = type;
    }

    private String number;

    private PhoneType type;

    // do not serialized
    transient private User user;

    @Column(name = "NUMBER")
    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    @Column(name = "TYPE", nullable = false)
    @Enumerated(EnumType.STRING)
    public PhoneType getType() {
        return type;
    }

    public void setType(PhoneType type) {
        this.type = type;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USER_ID")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public String toString() {
        return number;
    }

    @Override
    public void prepareToSerialize() {
    }
}
